package com.power.controller;

import com.power.model.Result;
import com.power.service.SendService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @Description 短信发送接口
 * @Author dingchunlin
 * @Date 2024/07/21 10:23
 * @Version 1.0.0
 */
@Api(tags = "短信发送接口")
@RestController
@RequestMapping("/p/sms")
public class SendController {

    @Autowired
    private SendService sendService;

    /**
     * 获取短信验证码
     * @param map 包含手机号和验证码的map
     * @return 成功或失败的结果
     */
    @ApiOperation(value = "获取短信验证码")
    @PostMapping("/send")
    public Result<String> sendPhoneCode(@RequestBody Map<String, Object> map) {
        sendService.sendPhoneCode(map);
        return Result.success("短信发送成功");
    }

    /**
     * 用户绑定手机号
     * @param map 包含手机号和验证码的map
     * @return 成功或失败的结果
     */
    @ApiOperation(value = "用户绑定手机号")
    @PostMapping("/savePhone")
    public Result<String> saveMsgPhone(@RequestBody Map<String, Object> map) {
        Boolean save = sendService.saveMsgPhone(map);
        return Result.handle(save);
    }

}
